package xyz.poke.business.tool.common;

import java.io.Serializable;

/**
 * @author 迫壳
 * @date 2024/3/3 9:19
 */
public enum ErrorCode implements Serializable {

    /**
     * 用于系统错误码
     */
    SUCCESS(200, "成功"),
    FAIL(500, "全局异常"),
    CONFLICT(409, "数据冲突"),
    NOT_EXIST(404, "请求数据不存在"),
    PARAM_ERROR(400, "参数错误"),
    UNAUTHORIZED(401, "暂未登录,token已过期"),
    FORBIDDEN(403, "没有相关权限"),
    ;

    private final int code;
    private final String message;

    ErrorCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getMessage() {
        return this.message;
    }

    public Integer getCode(){
        return this.code;
    }

    public static String getMessage(Integer code){
        String rel = "";
        for (ErrorCode subType:ErrorCode.values()) {
            if(subType.getCode().equals(code)){
                return subType.getMessage();
            }
        }
        return rel;
    }

}
